#include"Socket.hpp"

using namespace SocketModule;

int main(int argc,char* argv[])
{
    if(argc!=3)
    {
        cout<<"client serverip serverport"<<endl;
        return 1;
    }
    shared_ptr<Socket> sock=make_shared<TcpSocket>();
    sock->SockCreation(SockType::ORDINARY_SOCK);
    sock->Bind();

    struct sockaddr_in serveraddr;
    serveraddr.sin_family=AF_INET;
    serveraddr.sin_addr.s_addr=inet_addr(argv[1]);
    serveraddr.sin_port=htons(stoi(argv[2]));

    sock->Connect(&serveraddr);

    int n=10;
    while(n--)
    {
        cout<<"client# ";
        string in;
        string out;
        getline(cin,out);
        sock->Sendto(out,&serveraddr);
        sock->Send(out);
        sock->Recv(in);


        sock->Recvfrom(in,nullptr);
        cout<<in<<endl;
        cout<<sock->GetSockfd()<<endl;
        cout<<sock->GetPort()<<endl;
        cout<<sock->GetIp()<<endl;

    }

    return 0;
}